home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / cop01.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  6KB  |  239 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. unsigned char *cop01_videoram;
  13. size_t cop01_videoram_size;
  14.  
  15. static unsigned char cop01_scrollx[1];
  16. static unsigned char spritebank = 0;
  17. static int flipscreen;
  18.  
  19. static struct osd_bitmap *tmpbitmap2;
  20.  
  21.  
  22.  
  23. void cop01_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  24. {
  25.     int i;
  26.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  27.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  28.  
  29.     for (i = 0;i < Machine->drv->total_colors;i++)
  30.     {
  31.         int bit0,bit1,bit2,bit3;
  32.  
  33.         bit0 = (color_prom[0] >> 0) & 0x01;
  34.         bit1 = (color_prom[0] >> 1) & 0x01;
  35.         bit2 = (color_prom[0] >> 2) & 0x01;
  36.         bit3 = (color_prom[0] >> 3) & 0x01;
  37.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  38.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  39.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  40.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  41.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  42.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  43.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  44.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  45.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  46.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  47.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  48.  
  49.         color_prom++;
  50.     }
  51.  
  52.     color_prom += 2*Machine->drv->total_colors;
  53.     /* color_prom now points to the beginning of the lookup tables */
  54.  
  55.     /* characters use colors 0-15 */
  56.     for (i = 0;i < TOTAL_COLORS(0);i++)
  57.         COLOR(0,i) = (*(color_prom++) & 0x0f);    /* ?? */
  58.  
  59.     /* background tiles use colors 192-255 */
  60.     for (i = 0;i < TOTAL_COLORS(1);i++)
  61.         COLOR(1,i) = i + 192;
  62.  
  63.     /* sprites use colors 128-143 */
  64.     for (i = 0;i < TOTAL_COLORS(2);i++)
  65.         COLOR(2,i) = (*(color_prom++) & 0x0f) + 128;
  66. }
  67.  
  68.  
  69.  
  70. /***************************************************************************
  71.  
  72.   Start the video hardware emulation.
  73.  
  74. ***************************************************************************/
  75. int cop01_vh_start(void)
  76. {
  77.     if (generic_vh_start() != 0)
  78.         return 1;
  79.  
  80.     if ((tmpbitmap2 = osd_create_bitmap(2*Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  81.     {
  82.         generic_vh_stop();
  83.         return 1;
  84.     }
  85.  
  86.     return 0;
  87. }
  88.  
  89.  
  90.  
  91. /***************************************************************************
  92.  
  93.   Stop the video hardware emulation.
  94.  
  95. ***************************************************************************/
  96.  
  97. void cop01_vh_stop(void)
  98. {
  99.     osd_free_bitmap(tmpbitmap2);
  100.     generic_vh_stop();
  101. }
  102.  
  103.  
  104.  
  105. WRITE_HANDLER( cop01_scrollx_w )
  106. {
  107.     cop01_scrollx[offset] = data;
  108. }
  109.  
  110.  
  111. WRITE_HANDLER( cop01_gfxbank_w )
  112. {
  113.     /* bits 0 and 1 coin counters */
  114.     coin_counter_w(0,data & 1);
  115.     coin_counter_w(1,data & 2);
  116.  
  117.     /* bit 2 flip screen */
  118.     if (flipscreen != (data & 0x04))
  119.     {
  120.         flipscreen = data & 0x04;
  121.         memset(dirtybuffer,1,videoram_size);
  122.     }
  123.  
  124.     /* bits 4 and 5 select sprite bank */
  125.     spritebank = (data & 0x30) >> 4;
  126.  
  127. logerror("gfxbank = %02x\n",data);
  128. }
  129.  
  130.  
  131.  
  132.  
  133. /***************************************************************************
  134.  
  135.   Draw the game screen in the given osd_bitmap.
  136.   Do NOT call osd_update_display() from this function, it will be called by
  137.   the main emulation engine.
  138.  
  139. ***************************************************************************/
  140. void cop01_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  141. {
  142.     int offs;
  143.  
  144.  
  145.     /* draw the background */
  146.     for (offs = videoram_size - 1;offs >= 0;offs--)
  147.     {
  148.         if (dirtybuffer[offs])
  149.         {
  150.             int sx,sy;
  151.  
  152.             dirtybuffer[offs] = 0;
  153.  
  154.             sx = offs % 64;
  155.             sy = offs / 64;
  156.             if (flipscreen)
  157.             {
  158.                 sx = 63 - sx;
  159.                 sy = 31 - sy;
  160.             }
  161.  
  162.             drawgfx(tmpbitmap2,Machine->gfx[1],
  163.                     videoram[offs] + ((colorram[offs] & 0x03) << 8),
  164.                     (colorram[offs] & 0x0c) >> 2,
  165.                     flipscreen,flipscreen,
  166.                     8*sx,8*sy,
  167.                     0,TRANSPARENCY_NONE,0);
  168.         }
  169.     }
  170.  
  171.     /* copy the background graphics */
  172.     {
  173.         int scrollx;
  174.  
  175.  
  176.         if (flipscreen)
  177.             scrollx = (cop01_scrollx[0] + 256 * cop01_scrollx[1]) - 256;
  178.         else
  179.             scrollx = -(cop01_scrollx[0] + 256 * cop01_scrollx[1]);
  180.  
  181.         copyscrollbitmap(bitmap,tmpbitmap2,1,&scrollx,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  182.     }
  183.  
  184.  
  185.     /* draw the sprites */
  186.     for (offs = 0;offs < spriteram_size;offs += 4)
  187.     {
  188.         int attr = spriteram[offs+2];
  189.         int numtile = spriteram[offs+1];
  190.         int flipx = attr & 4;
  191.         int sx,sy;
  192.  
  193.         if (numtile & 0x80)    /* high tiles are bankswitched */
  194.         {
  195.             if (spritebank & 1) numtile += 128;
  196.             else if (spritebank & 2) numtile += 256;
  197.         }
  198.  
  199.         sy = 240 - spriteram[offs];
  200.         sx = (spriteram[offs+3] - 0x80) + 256 * (attr & 1);
  201.         if (flipscreen)
  202.         {
  203.             sx = 240 - sx;
  204.             sy = 240 - sy;
  205.             flipx = !flipx;
  206.         }
  207.  
  208.         drawgfx(bitmap,Machine->gfx[2],
  209.                 numtile,
  210.                 (attr & 0xf0) >> 4,
  211.                 flipx,flipscreen,
  212.                 sx,sy,
  213.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  214.     }
  215.  
  216.  
  217.     /* draw the foreground characters */
  218.     for (offs = cop01_videoram_size - 1;offs >= 0;offs--)
  219.     {
  220.         int sx,sy;
  221.  
  222.  
  223.         sx = offs % 32;
  224.         sy = offs / 32;
  225.         if (flipscreen)
  226.         {
  227.             sx = 31 - sx;
  228.             sy = 31 - sy;
  229.         }
  230.  
  231.         drawgfx(bitmap,Machine->gfx[0],
  232.                 cop01_videoram[offs],
  233.                 0,    /* is there a color selector missing? */
  234.                 flipscreen,flipscreen,
  235.                 8*sx,8*sy,
  236.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,15);
  237.     }
  238. }
  239.